<?php

include 'Grocery_CRUD.php';

class ExCRUD extends grocery_CRUD {

    private $CI;

    public function __construct() {
        parent::__construct();
        $this->CI = & get_instance();
        $this->set_theme('flexigrid');
    }

    public function set_add($set) {
        $this->unset_add = $this->getBool($set);
    }

    public function set_edit($set) {
        $this->unset_edit = $this->getBool($set);
    }

    public function set_delete($set) {
        $this->unset_delete = $this->getBool($set);
    }

    public function set_field_readonly($crud, $fields) {
        foreach ($fields as $field) {
            $crud->field_type($field, 'readonly');
        }
    }

    public function set_field_hidden($crud, $fields) {
        foreach ($fields as $field) {
            $crud->field_type($field, 'hidden');
        }
    }

    public function standartCheck() {
        $ci = & get_instance();
        $ci->load->library("session");
        if (($ci->session->userdata("user_name") == "") || ($ci->session->userdata("user_name") == null)) {
            redirect('http://localhost/admin_ska');
        }
    }

    function getBool($set) {
        if ($set == 'true') {
            return false;
        } else {
            return true;
        }
    }

    function getURL() {
        $pageURL = 'http';
        if ($_SERVER["HTTPS"] == "on") {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        }
        return $pageURL = $_SERVER["REQUEST_URI"];
    }

    function extractURL($value) {
        $data = explode('/', (trim($_SERVER["REQUEST_URI"], "#")));
        $hasil = '/' . $data[3] . '/' . $data[4];
        return $hasil;
    }

}

?>
